package com.weixing.mall.pay;

import lombok.Data;

/**
 * @ClassName QueryResult
 * @Description
 * @Author Small
 * @Date 2019/11/29 20:20
 * @Version 1.0
 **/
@Data
public class NotifyResult {

    private static final String RETURN_SUCCESS = "SUCCESS";
    private static final String RETURN_FAIL = "FAIL";
    private static final String TRADE_SUCCESS = "SUCCESS";
    private static final String UNKONW_EXCEPTION = "UNKONW_EXCEPTION";
    /**
     * 验签失败
     */
    private static final String INVALID_SIGN = "INVALID_SIGN";



    /**
     * 错误码
     */
    private String errCode;
    /**
     * 通信状态
     */
    private String returnCode;
    /**
     * 错误信息
     */
    private String errMsg;
    /**
     * 交易状态
     */
    private String tradeState;

    private NotifyResp notifyResp;


    public NotifyResult() { }


    public NotifyResult(String returnCode, String errMsg, String errCode, String tradeState,NotifyResp notifyResp) {
        this.returnCode = returnCode;
        this.errMsg = errMsg;
        this.errCode = errCode;
        this.tradeState = tradeState;
        this.notifyResp = notifyResp;
    }


    /**
     * 方法描述:  交易成功
     * @Author Small
     * @Date 2019/11/28 16:46
     * @return com.weixing.mall.pay.PayResult
     */
    public static NotifyResult tradeSuccess(NotifyResp notifyResp) {
        return new NotifyResult(RETURN_SUCCESS, null, null, TRADE_SUCCESS,notifyResp);
    }



    /**
     * 方法描述: 交易未成功
     * @Author Small
     * @Date 2019/11/28 16:46
     * @return com.weixing.mall.pay.PayResult
     */
    public static NotifyResult tradeNotSuccess(String tradeStatus,String tradeMsg) {
        return new NotifyResult(RETURN_SUCCESS, null, tradeStatus, tradeStatus,null);
    }

    /**
     * 方法描述: 接口调用失败
     * @Author Small
     * @param errCode  错误代码
     * @param errMsg   失败原因
     * @Date 2019/11/28 16:48
     * @return com.weixing.mall.pay.PayResult
     */
    public static NotifyResult fail(String errCode, String errMsg) {
        return new NotifyResult(RETURN_FAIL, errMsg, errCode, null,null);
    }

    /**
     * 方法描述: 接口验签失败
     * @Author Small
     * @Date 2019/11/28 16:48
     * @return com.weixing.mall.pay.PayResult
     */
    public static NotifyResult invalidSign() {
        return new NotifyResult(RETURN_SUCCESS, "验签失败", INVALID_SIGN, null,null);
    }

    /**
     * 方法描述: 接口调用失败
     * @Author Small
     * @Date 2019/11/28 16:48
     * @return com.weixing.mall.pay.PayResult
     */
    public static NotifyResult unknowException() {
        return new NotifyResult(UNKONW_EXCEPTION, "系统未知异常", null, null,null);
    }



    /**
     * 方法描述: 交易是否是否成功
     * @Author Small
     * @param
     * @Date 2019/11/28 16:49
     * @return boolean
     */
    public boolean isTradeSuccess() {
        return RETURN_SUCCESS.equals(this.returnCode) && TRADE_SUCCESS.equals(this.getTradeState());
    }

    /**
     * 方法描述: 通信是否是否成功
     * @Author Small
     * @param
     * @Date 2019/11/28 16:49
     * @return boolean
     */
    public boolean isSuccess(){
        return RETURN_SUCCESS.equals(this.returnCode);
    }

    /**
     * 方法描述:是否验签成功
     * @Author Small
     * @param
     * @Date 2019/12/11 11:47
     * @return boolean
    */
    public boolean isSignVerifyFail(){
        return RETURN_SUCCESS.equals(this.returnCode) && INVALID_SIGN.equals(this.getErrCode());
    }


    public static void main(String[] args) {
        System.out.println(INVALID_SIGN.equals(null));
    }

}
